package DEEPERsource.DEEPERsource.source.corpus;

import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.ListIterator;

import javax.naming.OperationNotSupportedException;

import parser.Parser;


import deeper.Interaction;

/**
 * Component implementation of the Composite pattern.
 * Provides basic functionality for all text elements - 
 * Corpus, Abstract, Sentence
 * @author tfayruzo
 *
 */
public abstract class Text {
	
	protected String id;
	
	protected String originalId;
	
	protected Text parent;
	
	public String id(){
		return id;
	}
	
	public String originalId(){
		return originalId;
	}
	
	/**
	 * default implementation returns iterator over the empty list
	 * to be overloaded in composite class.
	 * List iterator is used to enforce the ordering of childeren
	 */	
	@SuppressWarnings("unchecked")
	public ListIterator<Text> iterator(){
		return Collections.EMPTY_LIST.listIterator();
	}
	
	/**
	 * adds new element to the end of children list
	 */ 
	public void add(Text text) throws OperationNotSupportedException{
		ListIterator<Text> i = iterator();
		while(i.hasNext())
			i.next();
		i.add(text);
		text.parent = this;
	}
	
	public Text parent(){
		return parent;
	}
	
	public abstract Collection<Interaction> interactions();
	
	//parsing routine depends on the concrete class
	public abstract void parse(Parser parser, String...params);
}
